<%= form_for @resource, :url => (@url_override || (@resource.persisted? ? refinery.admin_resource_path(@resource) : refinery.admin_resources_path)),
             :html => { :multipart => true },
             :as => 'resource' do |f| %>

  <%= render '/refinery/admin/error_messages',
             :object => @resource,
             :include_object_name => false %>

  <%= render '/refinery/admin/locale_picker', :current_locale => Globalize.locale if @resource.persisted? %>

  <div class="field" id="file">
    <span class='label_with_help'>
      <%= f.label :file, t('.resource_file') %>
      <%= refinery_help_tag t('.maximum_file_size', :bytes => number_to_human_size(Refinery::Resources.max_file_size)) %>
    </span>

    <% if action_name =~ /(edit)|(update)/ %>
      <%= action_label :download, @resource.url, @resource.title, { tooltip: t('.download_current') } %>
      <em><%= t('.or')%></em><%= t('.replace') %>
      <%= f.file_field :file %>
    <% else %>
      <% # we must only hint at multiple when it's a *new* record otherwise update fails. %>
      <%= f.file_field :file, :multiple => (true unless @resource.persisted?) %>
    <% end %>
  </div>

  <div class="field" id="title">
    <span class='label_with_help'>
      <%= f.label :resource_title, t('.resource_title') %>
      <%= refinery_help_tag t('.resource_title_help') %>
    </span>
    <%= f.text_field :resource_title, placeholder: t('.resource_title') %>
  </div>

  <%= render '/refinery/admin/form_actions', :f => f,
             :continue_editing => false,
             :hide_cancel => (@app_dialog or action_name == 'insert' or from_dialog?),
             :delete_title => t('delete', :scope => 'refinery.admin.resources'),
             :delete_confirmation => (t('message', :scope => 'refinery.admin.delete',
                                      :title => @resource.title) if @resource.persisted?),
             cancel_url: refinery.admin_resources_path -%>

  <% if @app_dialog -%>
    <input type="hidden" name="app_dialog" value="<%= @app_dialog %>" />
    <input type="hidden" name="field" value="<%= @field %>" />
    <input type="hidden" name="update_resource" value="<%= @update_resource %>" />
    <input type="hidden" name="update_text" value="<%= @update_text %>" />
    <input type="hidden" name="thumbnail" value="<%= @thumbnail %>" />
    <input type="hidden" name="callback" value="<%= @callback %>" />
    <input type="hidden" name="conditions" value="<%= @conditions %>" />
    <input type="hidden" name="current_link" value="<%= @current_link %>" />
  <% end -%>
<% end -%>
<% content_for :javascripts do %>
  <script>
    $(document).ready(function(){
      link_dialog.init();
    });
  </script>
<% end if from_dialog? %>